package com.example.fruit;

import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.widget.RadioGroup;
import android.widget.Toast;

import com.example.fragment.CartFragment;
import com.example.fragment.CategoryFragment;
import com.example.fragment.GuoshiFragment;
import com.example.fragment.HomeFragment;
import com.example.fragment.SmileFragment;
import com.example.utils.FragmentTabUtils;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ContentView;
import com.lidroid.xutils.view.annotation.ViewInject;

import java.util.ArrayList;
import java.util.List;

//@ContentView(R.layout.activity_main)
public class MainActivity extends ActionBarActivity implements FragmentTabUtils.OnRgsExtraCheckedChangedListener {


    private List<Fragment> list;
//    @ViewInject(R.id.gRaddio)
    private RadioGroup rGroup;
    private long time;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
       // ViewUtils.inject(this);
        initViewPager();
    }

    private void initViewPager() {
        list=new ArrayList<Fragment>();
        list.add(new HomeFragment());
        list.add(new CategoryFragment());
        list.add(new SmileFragment());
        list.add(new CartFragment());
        list.add(new GuoshiFragment());

        FragmentTabUtils  ftUtils=new FragmentTabUtils(getSupportFragmentManager(),list,R.id.fragentmId, (RadioGroup) findViewById(R.id.gRaddio));
        ftUtils.setOnRgsExtraCheckedChangedListener(this);

    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        long currentTime=System.currentTimeMillis();
        if (keyCode==KeyEvent.KEYCODE_BACK){
            if(currentTime-time>1*10000){
                Toast.makeText(this,"连续点击退出",Toast.LENGTH_LONG).show();

            }

        }
        return super.onKeyDown(keyCode, event);
    }


    @Override
    public void onBackPressed() {
        super.onBackPressed();
    }

    @Override
    public void OnRgsExtraCheckedChanged(RadioGroup radioGroup, int checkedId, int index) {

    }
}
